﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace RedSand.Site
{
    public static class GlobalClass
    {
        public static string GetImageUrl(this string input)
        {
            if (string.IsNullOrWhiteSpace(input))
                return "/content/images/fe/default_image.png";
            return input;
        }
        /// <summary>
        /// Get image url
        /// </summary>
        /// <param name="input">Name</param>
        /// <param name="type">image type : 0 - no image , 1 - no avata</param>
        /// <returns></returns>
        public static string GetImageUrl(this string input, int type)
        {
            if (string.IsNullOrWhiteSpace(input))
                switch (type)
                {
                    case 0:
                        input = "/content/images/fe/default_image.png";
                        break;
                    case 1:
                        input = "/content/images/fe/avt-no-images.jpg";
                        break;
                }
            return input;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <param name="position"></param>
        /// <param name="lenght"></param>
        /// <returns></returns>
        public static string SubStringExtended(this string input, int startIndex, int length)
        {
            int inpLength = input.Length;
            if (startIndex >= length) return string.Empty;
            if (startIndex + length >= inpLength) return input.Substring(startIndex);
            return input.Substring(startIndex, length);
        }

        public static string SubString2(this string input, int startIndex, int length)
        {
            int inpLength = input.Length;
            if (startIndex >= length) return string.Empty;
            if (startIndex + length >= inpLength) return input.Substring(startIndex);
            return input.Substring(startIndex, length);
        }


        /// <summary>
        /// Get date time by Language
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string GetDate(this DateTime? input)
        {
            if (input.HasValue)
            {
                switch (RedSand.Web.Language.RsLanguage.LanguageCode)
                {
                    case "vi": return input.Value.ToString("dd/MM/yyyy");
                }
            }
            return string.Empty;
        }

    }
}